#!/usr/bin/env python

"""
Compares two component history files in the testcase directory
"""

from standard_script_setup import *

from CIME.case       import Case
from CIME.hist_utils import compare_test

###############################################################################
def parse_command_line(args, description):
###############################################################################
    parser = argparse.ArgumentParser(
        usage="""\n{0} suffix1 suffix2 [<casedir>] [--verbose]
OR
{0} --help

\033[1mEXAMPLES:\033[0m
    \033[1;32m# Setup case \033[0m
    > {0}
""".format(os.path.basename(args[0])),
        description=description,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    CIME.utils.setup_standard_logging_options(parser)

    parser.add_argument("suffix1",
                        help="The suffix of the first set of files")

    parser.add_argument("suffix2",
                        help="The suffix of the second set of files")

    parser.add_argument("caseroot", nargs="?", default=os.getcwd(),
                        help="Case directory")

    args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)

    return args.suffix1, args.suffix2, args.caseroot

###############################################################################
def _main_func(description):
###############################################################################
    suffix1, suffix2, caseroot = parse_command_line(sys.argv, description)
    with Case(caseroot) as case:
        success, comments = compare_test(case, suffix1, suffix2)
        print(comments)

    sys.exit(0 if success else 1)

if __name__ == "__main__":
    _main_func(__doc__)
